import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import remove from '@dfeidao/atom-web/local/remove';
import nodejs from "@dfeidao/atom-web/msg/nodejs";
import render from "@dfeidao/atom-web/render/render";
import s_get from '@dfeidao/atom-web/storage/get';
// import whoami from '@dfeidao/atom-web/msg/whoami';
// import { send_msg as url, get_user_info } from './config';


import p003 from './p003';

import p001 from './p001';
export default async function a007(fd: IFeidaoAiBrowserComponent, args: Event) {
	// fd.data.uscode =
	const usercode = args;
	// const user = await whoami(get_user_info);
	// console.log(user)
	const prid = await s_get('productid');

	const query = {

		productid: prid,
		usercode

	};

	const res = await nodejs<{ dataArray: object[] }>('consumer/zj-000004/consumer-find1', query);

	const tb = res.dataArray;
	const data = tb.map((v) => {
		return { ...v, v: JSON.stringify(v) };
	});
	const p3 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	const p1 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	if (res.dataArray.length === 0) {
		p1.classList.add('display-n');
		p3.classList.remove('display-n');
		render(fd, '', p001, 'p001', 'inner');
		render(fd, '', p003, 'p003', 'inner');
	} else {
		p3.classList.add('display-n');
		p1.classList.remove('display-n');
		render(fd, data, p001, 'p001', 'inner');
	}
	// p3.classList.add('display-n');
	// render(fd, data, p001, 'p001', 'inner');
	remove(fd, 'rolef');
	remove(fd, 'w_id');
}
